package com.xncoding.socket.socket.client.javax;

import org.junit.Test;

import javax.websocket.ContainerProvider;
import javax.websocket.DeploymentException;
import javax.websocket.Session;
import javax.websocket.WebSocketContainer;
import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;

public class javaxTets {
    @Test()
    void testJavax() throws DeploymentException, IOException, URISyntaxException {
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        URI uri = new URI("/websocket/11");
        Session session = container.connectToServer(JavaxWebSocketClientEndpoint.class, uri);
        //发送文本消息
        session.getAsyncRemote().sendText("文本消息");

//发送二进制消息
//        session.getAsyncRemote().sendBinary(ByteBuffer message);

//发送对象消息，会尝试使用Encoder编码
//        session.getAsyncRemote().sendObject(Object message);

//发送ping
//        session.getAsyncRemote().sendPing(ByteBuffer buffer);

//发送pong
//        session.getAsyncRemote().sendPong(ByteBuffer buffer);
    }

    public static void main(String[] args) throws URISyntaxException, DeploymentException, IOException {
        WebSocketContainer container = ContainerProvider.getWebSocketContainer();
        URI uri = new URI("/websocket/11");
        Session session = container.connectToServer(JavaxWebSocketClientEndpoint.class, uri);
        //发送文本消息
        session.getAsyncRemote().sendText("文本消息");
    }

}
